<?php

/**
 * Controller_comment
 */

class Controller_comment extends MyApp {

	public function __construct()
	{
		parent::__construct();
	
		$this->model->log   	= YOU::loadModel('log');
	}
    /** 首页 **/
    public function actionIndex ()
    {

    }

    /** 留言列表 **/
    public function actionList ()
    {
    	// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);
		
        // 分页     
        YOU::loadLib('page', "", '0');

        $tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_comment`");
        $count = $tmp['count'];
        $page_total = ceil($count/PAGE_LIMIT);

        // 当前页
        $p = intval($_GET['p']);
        if ($p == 0){
            $p  = 1;
        }
        if ($p > 1){
            $start = PAGE_LIMIT * ($p-1);
        }else{
            $start = 0;
        }

        $comment_lists = $this->db->fetchAll("SELECT * FROM `tbl_comment` ORDER BY comment_id DESC LIMIT {$start}, ".PAGE_LIMIT."");


        $page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
        $page->next_page   = '下一页>';
        $page->pre_page    = '<上一页';
        $page->style_path  = "static/page_style";

        $this->tpl->assign("page", $page->show(4, "yahoo"));
        $this->tpl->assign("comment_lists", $comment_lists);
        $this->tpl->display();
    }                          
    
}

?>